****************************************
** Replication Code ********************
****************************************

* load data
cd "C:\Users\timba\OneDrive - Universität Bayreuth (1)\Uni\Research General\Inequality and Protests\Empirics"
use "master\alldata.dta", replace

label variable ccc_count "Protest CCC"
label variable org_s "R: Organizations"
label variable network_s "R: Online Network"
label variable monetary_s "R: Monetary Means"
label variable shooting_black "Police Shooting B."
label variable unemployed "Unemployment"
label variable gini "Gini"
label variable log_population "Log Population"
label variable ln_density "Density"
label variable no_degree "No school degree"
label variable college_students_pc "College Students p.c."
label variable im_since_1990 "Share immigrants"
label variable youth_group "Share Aged 20-39"
label variable white "Pop. share white"
label variable black "Pop. share black"
label variable center_1 "Center 1"
label variable center_2 "Center 2"
label variable election_clos "Election Closeness"
label variable gri_s "Gri."
label variable rmp_s "RMT"


***********************************
*** Globals
***********************************

* dependent variable and variables of interest
global w "org_s network_s monetary_s c.org_s#c.network_s"
global w2 "shooting_black unemployed gini"

* covariates
global vars "log_population ln_density no_degree college_students_pc im_since_1990 youth_group white black center_1 center_2 election_clos"


***********************************
*** Correlations
***********************************

gen org_s_low_network_s_high = 0
replace org_s_low_network_s_high = 1 if org_s <-.6440399 & network_s > .6582008
cor org_s_low_network_s_high gri_s org_s network_s monetary_s $w2 $vars

* export correlation matrix to LaTeX
correlate org_s_low_network_s_high gri_s org_s network_s monetary_s $w2 $vars if year == 2022
matrix C = r(C)
esttab matrix(C, fmt(%9.3f)) using "correlation_matrix.tex", ///
    replace ///
    title("Correlation Matrix") ///
    nomtitles ///
    nonumbers label

* export summary stats
estpost summarize org_s_low_network_s_high gri_s org_s network_s monetary_s $w2 $vars if year == 2022

esttab using "summary_stats.tex", ///
    replace ///
    cells("count(fmt(0)) mean(fmt(%9.3f)) sd(fmt(%9.3f))") ///
    label ///
    noobs ///
    nonumber ///
    nomtitle ///
    title("Summary Statistics") ///
    collabels("N" "Mean" "SD")

	

***********************************
*** Baseline
***********************************

* setting
global year "if year == 2022"
global pop_cap "& population > 30000"


*** regressions
* standard
qui eststo poisson1: poisson ccc_count $w $w2 $vars $year, robust

* population cap
qui eststo poisson2: poisson ccc_count $w $w2 $vars $year $pop_cap, robust

* data base
qui eststo poisson3: poisson acled_count $w $w2 $vars $year, robust

* years 
qui eststo poisson4: poisson ccc_count $w $w2 $vars if year == 2020, robust
qui eststo poisson5: poisson ccc_count $w $w2 $vars if year == 2018, robust

* summary
global export "using out.tex"
global export ""
esttab poisson1 poisson2 poisson3 poisson4 poisson5 $export, star( + 0.20 * 0.10 ** 0.05 *** 0.010) b(3) se(3) mtitles("Baseline" "Pop Cap" "ACLED" "2020" "2018") keep($w $w2 $vars) replace label scalars(r2_p) eform

* marginal effects interaction term
qui eststo poisson1: poisson ccc_count $w $w2 $vars $fe $year, robust
margins, dydx(org_s) atmeans
margins, dydx(network_s) atmeans
sum org_s network_s if year == 2022, detail
margins, dydx(org_s) at(network_s = (-1.831198 1.324098)) atmeans
margins, dydx(network_s) at(org_s = (-1.050802 1.914158)) atmeans


***********************************
*** Interaction
***********************************

* dependent variable and variables of interest
global w "org_s network_s monetary_s"

* covariates
global vars "log_population ln_density no_degree college_students_pc im_since_1990 youth_group white black center_1 center_2 election_clos"

* setting
global year "if year == 2022"


*** regressions
* standard
global w2 "gri_s"
qui eststo poisson1: poisson ccc_count $w $w2 $vars $fe $year, robust

* org
global w2 "gri_s c.gri_s#c.org_s"
qui eststo poisson2: poisson ccc_count $w $w2 $vars $fe $year, robust

* network
global w2 "gri_s c.gri_s#c.network_s"
qui eststo poisson3: poisson ccc_count $w $w2 $vars $fe $year, robust

* monetary
global w2 "gri_s c.gri_s#c.monetary_s"
qui eststo poisson4: poisson ccc_count $w $w2 $vars $fe $year, robust

* all
global w2 "gri_s c.gri_s#c.org_s c.gri_s#c.network_s c.gri_s#c.monetary_s"
qui eststo poisson5: poisson ccc_count $w $w2 $vars $fe $year, robust

* rmp
global w "rmp_s"
global w2 "gri_s c.gri_s#c.rmp_s"
qui eststo poisson6: poisson ccc_count $w $w2 $vars $year, robust


* summary
global export "using out.tex"
global export ""
esttab poisson1 poisson2 poisson3 poisson4 poisson5 poisson6 $export, star( + 0.20 * 0.10 ** 0.05 *** 0.010) b(3) se(3) mtitles("Baseline" "Org." "Network" "Monetary" "All" "RMP") replace label scalars(r2_p) eform


* INTERACTION TERM (IN PROGRESS)
global w "rmp_s"
global w2 "gri_s c.gri_s#c.rmp_s"
eststo poisson6: poisson ccc_count $w $w2 $vars $year, robust
sum gri_s rmp_s if year == 2022, detail 
margins, dydx(gri_s) 
margins, dydx(gri_s) at(rmp_s = (-1.3(0.2)1.9)) atmeans
mplotoffset, name(Gri, replace) xsize(5) ysize(4)  offset(0.1)  ///
	yscale(range(0 4)) ylabel(0(1)4, grid) xlabel(-1.3(0.4)1.8) title("A: Conditional marginal effects grievances") legend(off ) 
margins, dydx(rmp_s) at(gri_s = (-1.2(0.2)1.7)) atmeans
mplotoffset, name(RMT, replace) xsize(5) ysize(4)  offset(0.1) ///
	yscale(range(0 4)) ylabel(0(1)4, grid) xlabel(-1.2(0.4)1.6) title("B: Conditional marginal effects of resources") legend(off ) 
grc1leg2 Gri RMT, xsize(3.5) ysize(2) rows(1) cols(2) loff

sum gri_s rmp_s if year == 2022, detail 
margins, dydx(gri_s) at(rmp_s = (-1.295147 1.943901)) atmeans
margins, dydx(rmp_s) at(gri_s = (-1.202222 1.669438)) atmeans


***********************************
*** Movement Heterogeneity
***********************************

* dependent variable and variables of interest
global w "org_s network_s monetary_s c.org_s#c.network_s"
global w2 "shooting_black unemployed gini"

* covariates
global vars "log_population ln_density no_degree college_students_pc im_since_1990 youth_group white black center_1 center_2 election_clos"

* setting
global year "if year == 2022"

*** regressions
qui eststo poisson1: poisson racism $w $w2 $vars $year, robust
qui eststo poisson2: poisson policing $w $w2 $vars $year, robust
qui eststo poisson3: poisson environment  $w $w2 $vars $year, robust
margins, dydx(network_s) at(org_s = -1.050802)
qui eststo poisson4: poisson education $w $w2 $vars $year, robust
qui eststo poisson5: poisson guns  $w $w2 $vars $year, robust
qui eststo poisson6: poisson civil_rights  $w $w2 $vars $year, robust

* summary
global export "using out.tex"
global export ""
esttab poisson1 poisson2 poisson3 poisson4 poisson5 poisson6 $export, star( + 0.20 * 0.10 ** 0.05 *** 0.010) b(3) se(3) mtitles("Racism" "Policing" "Environment" "Education" "Guns" "Civil Rights") replace label scalars(r2_p) eform

	
***********************************
*** Robustness
***********************************
	
* dependent variable and variables of interest
global w "org_s network_s monetary_s c.org_s#c.network_s"
global w2 "shooting_black unemployed gini"

* covariates
global vars "log_population ln_density no_degree college_students_pc im_since_1990 youth_group white black center_1 center_2 election_clos"

* FE
global fe "i.state"
global fe ""

* setting
global year "if year == 2022"
global pop_cap "& population > 30000"


* lagged variables: baseline
qui eststo poisson1_lag: poisson ccc_count org_s_2020 network_s_2020 monetary_s_2020 c.org_s_2020#c.network_s_2020 $w2 $vars $year, robust

* lagged variables: population cap
qui eststo poisson2_lag: poisson ccc_count org_s_2020 network_s_2020 monetary_s_2020 c.org_s_2020#c.network_s_2020 $w2 $vars $year $pop_cap, robust

* lagged variables: acled
qui eststo poisson3_lag: poisson acled_count ccc_count org_s_2020 network_s_2020 monetary_s_2020 c.org_s_2020#c.network_s_2020 $w2 $vars $year, robust

* negative binomial 
qui eststo nbreg: nbreg ccc_count $w $w2 $vars $year, robust

* Probit extensive margin
qui eststo probit: probit ccc_binary $w $w2 $vars $year, robust 

* poisson intensive margin
qui eststo poisson_int: poisson ccc_count $w $w2 $vars $year & ccc_count > 0 , robust

* summary
global export "using out.tex"
global export ""
esttab poisson1_lag poisson2_lag poisson3_lag nbreg probit poisson_int $export, star(* 0.10 ** 0.05 *** 0.010) b(3) se(3) mtitles("Lag Poi." "Lag Pop. Cap." "Lag ACLED" "Neg. Bin." "Probit ext. M." "Poi. int. M.") keep(org_s_2020 network_s_2020 monetary_s_2020 c.org_s_2020#c.network_s_2020 $w $w2 $vars) label replace scalars(r2 r2_p)












***********************************
*** Lagged resource dimensions
***********************************
	
global w "org_s network_s monetary_s c.org_s#c.network_s"
global w2 "shooting_black unemployed gini"

* covariates
global vars "log_population ln_density no_degree college_students_pc im_since_1990 youth_group white black center_1 center_2 election_clos"

keep fips_n year ccc_count acled_count population org_s network_s monetary_s shooting_black unemployed gini $vars

reshape wide ccc_count acled_count population org_s network_s monetary_s shooting_black unemployed gini $vars, i(fips_n) j(year)







* setting
global year ""
global pop_cap "if population2022 > 30000"

global w "org_s2020 network_s2020 monetary_s2020 c.org_s2020#c.network_s2020"
global w2 "shooting_black2022 unemployed2022 gini2022"

* covariates
global vars "log_population2022 ln_density2022 no_degree2022 college_students_pc2022 im_since_19902022 youth_group2022 white2022 black2022 center_12022 center_22022 election_clos2022"



*** regressions
* standard
qui eststo poisson1: poisson ccc_count2022 $w $w2 $vars, robust

* population cap
qui eststo poisson2: poisson ccc_count2022 $w $w2 $vars $pop_cap, robust

* data base
qui eststo poisson3: poisson acled_count2022 $w $w2 $vars $year, robust

global export "using out.tex"
global export ""
esttab poisson1 poisson2 poisson3  $export, star( + 0.20 * 0.10 ** 0.05 *** 0.010) b(3) se(3) mtitles("Baseline" "Pop Cap" "ACLED" "2020" "2018") keep($w $w2 $vars) replace label scalars(r2_p) eform



reg ccc_count2022 $w $w2 $vars, robust

ivregress 2sls ccc_count2022 $w2 $vars (org_s2022 network_s2022 monetary_s2022 c.org_s2022#c.network_s2022 = org_s2020 network_s2020 monetary_s2020 c.org_s2020#c.network_s2020), robust first




* setting
global year "if year == 2022"
global pop_cap "& population > 30000"

* lag structure
global w "org_s_2020 network_s_2020 monetary_s_2020 c.org_s_2020#c.network_s_2020"

*** regressions
* standard
qui eststo poisson1: poisson ccc_count $w $w2 $vars $year, robust

* population cap
qui eststo poisson2: poisson ccc_count $w $w2 $vars $year $pop_cap, robust

* data base
qui eststo poisson3: poisson acled_count $w $w2 $vars $year, robust

* summary
global export "using out.tex"
global export ""
esttab poisson1 poisson2 poisson3 $export, star(* 0.10 ** 0.05 *** 0.010) b(3) se(3) mtitles("Baseline" "Pop Cap" "ACLED" "2020" "2018") keep($w $w2 $vars) replace label scalars(r2_p) eform









***********************************
*** Robustness
***********************************
	
* dependent variable and variables of interest
global w "org_s network_s monetary_s c.org_s#c.network_s"
global w2 "shooting_black unemployed gini"

* covariates
global vars "log_population ln_density no_degree college_students_pc im_since_1990 youth_group white black center_1 center_2 election_clos"

* FE
global fe "i.state"
global fe ""

* setting
global year "if year == 2022"
global pop_cap "& population > 30000"

* OLS
qui eststo OLS: reg ln_ccc_count $w $w2 $vars $year, robust 

* negative binomial 
qui eststo nbreg: nbreg ccc_count $w $w2 $vars $year, robust

* OLS and poisson intensive margin
qui eststo OLS_int: reg ln_ccc_count $w $w2 $vars $year & ccc_count > 0, robust 
qui eststo poisson_int: poisson ccc_count $w $w2 $vars $year & ccc_count > 0 , robust

* Probit extensive margin
qui eststo probit: probit ccc_binary $w $w2 $vars $year, robust 

* State FE
qui eststo ols_fe: reg ln_ccc_count $w $w2 $vars i.state $year, robust 
qui eststo poisson_fe: poisson ccc_count $w $w2 $vars i.state $year , robust iter(200)

* summary
global export "using out.tex"
global export ""
esttab OLS nbreg OLS_int poisson_int probit ols_fe poisson_fe $export, star( + 0.20 * 0.10 ** 0.05 *** 0.010) b(3) se(3) mtitles("OLS" "Neg. Bin." "OLS int. M." "Poi. int. M." "Probit Ext. M." "OLS FE" "Poi. FE") keep($w $w2 $vars) label eform replace
esttab OLS nbreg OLS_int poisson_int probit  $export, star( + 0.20 * 0.10 ** 0.05 *** 0.010) b(3) se(3) mtitles("OLS" "Neg. Bin." "OLS int. M." "Poi. int. M." "Probit ext. M." "OLS FE" "Poi. FE") keep($w $w2 $vars) label replace scalars(r2 r2_p)





